package logic

import (
	"center/centerrpc/centerrpc"
	"context"

	"center/api/internal/svc"
	"center/api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type RealLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewRealLogic(ctx context.Context, svcCtx *svc.ServiceContext) *RealLogic {
	return &RealLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *RealLogic) Real(req *types.RealRequest) (resp *types.Response, err error) {
	// todo: add your logic here and delete this line
	response, err := l.svcCtx.CenterRpc.Real(l.ctx, &centerrpc.RealRequest{
		UserId: int64(req.UserId),
		Card:   req.Card,
		Name:   req.Name,
	})
	if err != nil {
		return &types.Response{
			Message: err.Error(),
			Data:    nil,
			Code:    500,
		}, nil
	}

	return &types.Response{
		Message: "实名认证成功",
		Data:    response,
		Code:    200,
	}, nil
}
